package com.inspire.ijc.agent.utils;

import com.inspire.ijc.agent.IjcAgent;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author ：inspire
 * @date ：Created in 2023/4/14 10:20
 * @description：
 * @modified By：inspire
 * @version:
 */
public class FileUtils {
    public static final String DATE_PATTERN_NOMARK = "yyyy-MM-dd HH:mm:ss.SSS";
    public static final String DATE_PATTERN_NOMARK2 = "yyyy-MM-dd_HH-mm-ss-SSS";

    public static void outputContentToFile(StringBuffer sb,String fileName){
        FileWriter fw = null;
        try {
            File ijc_methodCallStack=new File(IjcAgent.IJC_OUTPUT_DIR,fileName+".txt");
            fw=new FileWriter(ijc_methodCallStack,true);
            fw.write(sb.toString());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if(fw!=null){
                    fw.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static String getCurrentDateStr(String pattern) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(date);
    }

    public static String convertTime(Date date,String pattern){
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(date);
    }
}
